<template>
  <div class="add-con">
    <BackTitle title="收货地址"></BackTitle>
    <!-- changeOrSeleted为真就是修改管理地址 -->
    <div class="addressList" v-if="changeOrSeleted===true ">
      <div class="address-item" v-for="(item,index) in nowUser.address" :key="index">
        <div class="address-msg" @click="changeAddress(item)">
          <h2 class="nameandtel">
            <span class="name">{{item.name}}</span>
            <span class="tel">{{item.tel}}</span>
          </h2>
          <p>{{item.province}} {{item.city}} {{item.county}}</p>
          <p>{{item.addressDetail}}</p>
        </div>
        <div class="defualt" v-show="item.isDefault">
          <div class="defualt-box">
            默认
          </div>
        </div>
        <div class="img">
          <p class="deleted" @click="deleted(index)"> 删除</p>
          <img src="imgs/icon-right.png" alt="">
        </div>
      </div>
    </div>
    <div class="addressList" v-else>
      <div class="address-item" v-for="(item,index) in nowUser.address" :key="index" @click="changeItem(index)">
        <div class="address-msg">
          <h2 class="nameandtel">
            <span class="name">{{item.name}}</span>
            <span class="tel">{{item.tel}}</span>
          </h2>
          <p>{{item.province}} {{item.city}} {{item.county}}</p>
          <p>{{item.addressDetail}}</p>
        </div>
        <div class="defualt" v-show="item.isDefault">
          <div class="defualt-box">
            默认
          </div>
        </div>
        <div class="img">
          <img src="imgs/icon-right.png" alt="">
        </div>
      </div>
    </div>

    <!-- 添加收货地址 -->
    <div class="addAddress">
      <div class="button" @click="$router.push('/address/addAddress')">+ 添加收货地址</div>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapState } from 'vuex'
import { set } from '@/Storage'
export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: 'Add',
  data() {
    return {}
  },
  computed: {
    ...mapGetters(['nowUser']),
    ...mapState(['changeOrSeleted'])
  },
  methods: {
    changeItem(i) {
      this.$store.dispatch('changeAddress', i)
      this.$router.back()
    },
    // 修改地址
    changeAddress(data) {
      set('addressList', data)
      this.$router.push('/address/addAddress')
    },
    // 删除地址
    deleted(i) {
      this.$store.commit('DELETEDADDRESS', i)
    }
  }
}
</script>

<style lang='less' scoped>
.add-con {
  font-size: 28px;
  .addressList {
    width: 720px;
    margin: 15px auto 0;
    padding: 0 32px;
    .address-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 23px 0;
      width: 100%;
      .address-msg {
        .nameandtel {
          font-size: 34px;
          margin-bottom: 10px;
          .name {
            margin-right: 30px;
          }
        }
      }
      .img {
        text-align: right;
        img {
          width: 30px;
          height: 30px;
        }
        .deleted {
          margin-bottom: 20px;
          color: #999;
        }
      }
      .defualt {
        padding-right: 50px;
        .defualt-box {
          width: 80px;
          border: 1px solid #ff7d00;
          padding: 5px 10px;
          color: #ff7d00;
        }
      }
    }
  }
  .addAddress {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    background-color: #fff;
    padding: 12px 32px;
    .button {
      width: 686px;
      height: 72px;
      background: linear-gradient(46deg, #ff7d00, #ff5934);
      border-radius: 35px;
      margin: 0 auto;
      color: #fff;
      line-height: 72px;
      text-align: center;
      font-weight: 700;
    }
  }
}
</style>
